import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.blue[900], fontFamily: 'Roboto'),
      home: LoginPage(),
    );
  }
}

class LoginPage extends StatelessWidget {
  final GlobalKey<FormState> _loginFormKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Login')),
      body: Center(
        child: Padding(
          padding: EdgeInsets.all(16.0),
          child: Form(
            key: _loginFormKey,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextFormField(
                  decoration: InputDecoration(labelText: 'Email'),
                  validator: (value) {
                    if (value == null || value.isEmpty) {
                      return '请输入邮箱';
                    }
                    if (!RegExp(
                      r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+",
                    ).hasMatch(value)) {
                      return '请输入有效的邮箱地址';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 16.0),
                TextFormField(
                  decoration: InputDecoration(labelText: 'Password'),
                  obscureText: true,
                  validator: (value) {
                    if (value == null || value.isEmpty) {
                      return '请输入密码';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 16.0),
                ElevatedButton(
                  onPressed: () {
                    if (_loginFormKey.currentState!.validate()) {
                      // 处理登录逻辑
                      ScaffoldMessenger.of(
                        context,
                      ).showSnackBar(SnackBar(content: Text('登录表单验证通过')));
                    }
                  },
                  child: Text('Login'),
                ),
                TextButton(
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => RegistrationPage(),
                      ),
                    );
                  },
                  child: Text('Register'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class RegistrationPage extends StatelessWidget {
  final GlobalKey<FormState> _registrationFormKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Registration')),
      body: Center(
        child: Padding(
          padding: EdgeInsets.all(16.0),
          child: Form(
            key: _registrationFormKey,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextFormField(
                  decoration: InputDecoration(labelText: 'Email'),
                  validator: (value) {
                    if (value == null || value.isEmpty) {
                      return '请输入邮箱';
                    }
                    if (!RegExp(
                      r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+",
                    ).hasMatch(value)) {
                      return '请输入有效的邮箱地址';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 16.0),
                TextFormField(
                  decoration: InputDecoration(labelText: 'Password'),
                  obscureText: true,
                  validator: (value) {
                    if (value == null || value.isEmpty) {
                      return '请输入密码';
                    }
                    if (value.length < 6) {
                      return '密码长度至少为6位';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 16.0),
                ElevatedButton(
                  onPressed: () {
                    if (_registrationFormKey.currentState!.validate()) {
                      // 处理注册逻辑
                      ScaffoldMessenger.of(
                        context,
                      ).showSnackBar(SnackBar(content: Text('注册表单验证通过')));
                    }
                  },
                  child: Text('Register'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class ResumeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Resume')),
      body: ListView(
        padding: EdgeInsets.all(16.0),
        children: [
          ResumeSection(
            title: 'Personal Information',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  'John Doe',
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                ),
                Text(
                  'Software Engineer',
                  style: TextStyle(fontSize: 18, color: Colors.grey[700]),
                ),
                SizedBox(height: 8.0),
                Text('Email: johndoe@example.com'),
                Text('Phone: +1 (123) 456-7890'),
                Text('LinkedIn: linkedin.com/in/johndoe'),
                Text('GitHub: github.com/johndoe'),
              ],
            ),
          ),
          ResumeSection(
            title: 'Skills',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('• Programming Languages: Dart, Java, Python, C++'),
                Text('• Frameworks: Flutter, React, Spring Boot'),
                Text('• Tools: Git, Docker, Kubernetes, Jenkins'),
              ],
            ),
          ),
          ResumeSection(
            title: 'Work Experience',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('Senior Software Engineer at Tech Corp (2020 - Present)'),
                Text(
                  '• Led a team of 5 developers to deliver mobile applications.',
                ),
                Text('• Designed and implemented RESTful APIs using Node.js.'),
                Text('• Optimized application performance by 30%.'),
                SizedBox(height: 16.0),
                Text('Software Developer at Innovate Inc (2017 - 2020)'),
                Text('• Developed cross-platform mobile apps using Flutter.'),
                Text(
                  '• Collaborated with designers to implement UI/UX designs.',
                ),
              ],
            ),
          ),
          ResumeSection(
            title: 'Education',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  'Bachelor of Science in Computer Science, University of Tech (2013 - 2017)',
                ),
              ],
            ),
          ),
          ResumeSection(
            title: 'Achievements',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('• Published research paper on AI in IEEE Journal (2021)'),
                Text('• Won Best Hackathon Project Award at Tech Summit 2022'),
              ],
            ),
          ),
          ResumeSection(
            title: 'Certifications',
            content: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('• '), // 留空供填写
                Text('• '), // 留空供填写
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 新增模块化组件
class ResumeSection extends StatelessWidget {
  final String title;
  final Widget content;

  ResumeSection({required this.title, required this.content});

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.symmetric(vertical: 8.0),
      child: Padding(
        padding: EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 20,
                fontWeight: FontWeight.bold,
                color: Theme.of(context).primaryColor,
              ),
            ),
            SizedBox(height: 8.0),
            content,
          ],
        ),
      ),
    );
  }
}
